package com.leetcode.array;

public class Leetcode27 {
    public int removeElement(int[] nums, int val) {
        if (nums.length == 0) {
            return 0;
        }
        int k = 0;
        for (int i = 0 ; i < nums.length ; i ++) {
            if (nums[i] != val ) {
                if (k != i) {
                    int temp = nums[i];
                    nums[i] = nums[k];
                    nums[k] = temp;
                }
                k ++;
            }
        }
        return k;
    }

    public static void main(String[] args) {
        int[] arr = {3, 2, 2, 3};
        int count = new Leetcode27().removeElement(arr, 4);
        for (int i = 0 ; i < count ; i ++) {
            System.out.println(arr[i]);
        }
    }
}
